package com.xmlt.core.template.instance;

import org.w3c.dom.Element;

import com.xmlt.core.template.Template;
import com.xmlt.core.template.TemplateException;
import com.xmlt.core.template.TemplateManager;
import com.xmlt.core.template.TemplateParameter;

public abstract class AbstractInstance {
	private Element element;
	private TemplateManager manager;
	private Template template;
	protected TemplateParameter parameter;
	private boolean isMulti;
	private boolean isLink;
	private AbstractInstance parentInstance;

	public AbstractInstance(Element el, TemplateManager tm,
			TemplateParameter p, AbstractInstance parent) {
		element = el;
		manager = tm;
		parameter = p;
		parentInstance = parent;
	}

	public abstract AbstractInstance lookup(String path);

	public String getPath() {
		return InstanceUtils.getPath(this);
	}

	public AbstractInstance getParent() {
		return parentInstance;
	}

	public boolean isMultiInstance() {
		return isMulti;
	}

	public boolean isLink() {
		return isLink;
	}

	public Template getTemplate() {
		return template;
	}

	public void setTemplate(Template t) {
		template = t;
	}

	public TemplateManager getManager() {
		return manager;
	}

	public TemplateParameter getParameterReference() {
		return parameter;
	}

	public Element getElement() {
		return element;
	}

	public void setParent(AbstractInstance parent) {
		parentInstance = parent;
	}

	public void accept(IInstanceVisitor visitor) throws TemplateException {
		visitor.visit(this);
	}

}
